home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vesa24_2.zip / VGA24_2.ASM < prev    next >
Assembly Source File  |  1993-04-09  |  26KB  |  1,272 lines

  1. ;----------------------------vga.asm--------------------------------
  2. ; Modified for CIRRUS bank set and rgb input values 12/30/92
  3. ;
  4. ; Title: vga.asm   ren vga41.asm  ren vga24.asm by Don Lewis
  5. ; Date: 6/18/92
  6. ; Author: Randy Buckland (randy@ncsu.edu)
  7. ;
  8. ; Description:
  9. ;    This is a VERY basic set of routines to provide high speed SVGA
  10. ; graphics for IBM-PC compatibiles that have a VGA interface that supports
  11. ; a VESA driver. These routines assume a 256-color mode and will not work
  12. ; for any type of mode. The following routines are provided:
  13. ;
  14. ; vgainit(int vesa_mode)
  15. ; vgapoint(int row, int column, int pixel_value)
  16. ; vgahline(int row, int start_column, int end_column, int pixel_value)
  17. ; vgaline(int x1, int y1, int x2, int y2, int pixel_value)
  18. ; vgasetcolor(char *colors, int start, int count)
  19. ; vgafill(int row, int column, int width, int height, int pixel_value)
  20. ; vgarect(char *source, int source_width, int row, int column,
  21. ;        int width, int height)
  22. ;
  23. ;******** ADDED by Don Lewis, (djlewis@ualr.edu or djlewis@spider.ualr.edu)
  24. ; This works fine with 8bit VGA. Just pass color in red and rest is ignored.
  25. ; The original vgafill() was simply modified and vgapoint probably will be to.
  26. ; These modifications works with 8,15,16 and 24 bit VESA modes.
  27. ;
  28. ; vga_point(int,int,uchar r,uchar g,uchar b)
  29. ; vgapoint_rgb(int row, int column, uchar r, uchar g, uchar b)
  30. ; vgafill(int,int,int,int,uchar r,uchar g,uchar b)
  31. ; vgaline(int,int,int,int,uchar r,uchar g,uchar b)
  32. ;
  33. .model    large,c
  34. include macros.asm
  35.  
  36. ;
  37. ; Global data for the VGA support routines
  38. ;
  39. vgadata    segment word public 'VGADATA'
  40.  
  41. Block        dw    0        ; Current video memory block accessable
  42. BlockSz        dw    0        ; Size of a video block in K
  43. BlockShift    dw    0        ; Amount to shift bits by
  44. BlockEnd    dw    0        ; Last valid address in block
  45. BlockMask    dw    0        ; Mask used for block/offset operations
  46.  
  47. WinAddr        dw    0        ; Segment addr of window A block
  48. WinGran        dw    0        ; Window Granularity 12/10/92 djl
  49. ;WinFunc    dd    0        ; Far pointer to windowing function
  50. ScanWidth    dw    0        ; Width of a scan line
  51. BytesPerPixel   dw      0        ; BytesPerPixel  12/30/92 djl
  52. BitsPerPixel    dw    0        ; BitsPerPixel value
  53.  
  54. ShiftMask    dw    0        ; pixel shift mask 15 and 16bit modes
  55. shift        dw    0        ; pixel adjustment 15 and 16 bit modes
  56.  
  57. public screen_width,screen_height
  58. screen_width    dw    640        ; Width of screen
  59. screen_height    dw    480        ; Height of screen
  60.  
  61. public mouse_x, mouse_y
  62. mouse_x        dw    0
  63. mouse_y        dw    0
  64.  
  65. public text_height, text_drop
  66. text_height     dw      16
  67. text_drop       dw      4
  68.  
  69. vgadata    ends
  70.  
  71. vgacode segment word public 'VGACODE'
  72.     assume  cs:vgacode,ds:vgadata
  73.  
  74. ;
  75. ; Set current video memory block. This procedure assumes that ds already
  76. ; points to the vgadata segment. This routine will not modify any registers.
  77. ;
  78. ; Parameters:
  79. ;    - block number to change to
  80. ;
  81. vgablock proc near
  82.     push bp
  83.     mov bp,sp
  84.     push cx        ; stay with no register modification. djl
  85.     push dx
  86.  
  87.     mov dx,[bp+4]    ; Start of video memory
  88.     cmp dx,Block
  89.     je l1
  90.             ;Window Granularity must be used to adjust bank. djl
  91.     mov cx,WinGran  ;BankNum offset adjustment for cards of
  92.     shl dl,cl    ;varying window granularity. djl
  93.     mov Block,dx
  94.  
  95.     push ax
  96.     push bx
  97.  
  98.     mov ax,4f05h    ; VESA set memory block
  99.     mov bx,0000h    ; Set window A
  100.     int 10h
  101.  
  102.     pop bx
  103.     pop ax
  104. l1:
  105.     pop dx
  106.     pop cx        ; stay with no register modification. djl
  107.     mov sp,bp
  108.     pop bp
  109.     ret
  110. vgablock endp
  111.  
  112.  
  113.  
  114. ;
  115. ; Calculate block and offset values for a given row/column. Assumes that ds
  116. ; points to vgadata. Does NOT preserve registers. Returns block value in
  117. ; dx and offset in ax.
  118. ;
  119. ; Parameters:
  120. ;    - row value
  121. ;    - column value
  122. ;
  123. vgaoffset proc near
  124.     push bp
  125.     mov bp,sp
  126.  
  127.     mov ax,[bp+4]        ; Get row
  128.     mul ScanWidth        ; Get starting block and offset in dx:ax
  129.  
  130. ; New code for 24bit pixel offset
  131.     push dx
  132.     mov bx,ax        ; Save old ax
  133.     xor ax,ax
  134.     mov ax,[bp+6]             ; get column
  135. ;    mul word PTR BytesPerPixel
  136.     mul BytesPerPixel
  137.     and ax,7FFFh
  138.     add ax,bx        ; Add column offset
  139.     pop dx
  140.  
  141.     ;add ax,[bp+6]    ; Add start column offset
  142.     jnc la1
  143.     inc dx        ; Just crossed block boundery
  144. la1:
  145.     mov cx,BlockShift ; Get block size mask
  146.     cmp cx,0        ; Is block size 64K?
  147.     je la2           ; Yes, skip this section
  148.  
  149.     mov bx,ax    ; Save old ax
  150.     rol ax,cl
  151.     and ax,BlockMask ; Save high bits
  152.     rol dx,cl
  153.     add dx,ax    ; Add high bits to block value.
  154.  
  155.     mov ax,bx
  156.     rol ax,cl
  157.     or ax,BlockMask    ; Set undesirable bits
  158.     xor ax,BlockMask ; Clear bad bits
  159.     ror ax,cl
  160. ;
  161. ; Set active block to calculated block if needed
  162. ;
  163. la2:
  164.     cmp dx,Block
  165.     je la3
  166.     push dx
  167.     call vgablock
  168.     pop dx
  169. la3:
  170.  
  171.     mov sp,bp
  172.     pop bp
  173.     ret
  174. vgaoffset endp
  175.  
  176. ;
  177. ; Draw a single point in Red, Green, Blue for 15, 16 and 24 bit colour
  178. ; Added by Don Lewis to work with internal functions
  179. ; Parameters:
  180. ;    - Row of point
  181. ;    - Column of point
  182. ;    - r,g,b
  183. ;
  184. ; 24bit format bit pattern 'bbbbbbbbggggggggrrrrrrrr' 3 bytes
  185. ; 16bit                    '00000000bbbbbggggggrrrrr' 2 bytes
  186. ; 15bit                    '        0bbbbbgggggrrrrr' 2 bytes
  187. ;
  188. draw_rgb proc near
  189.     Prefix
  190.     push bx
  191.     push cx
  192.     push dx
  193. ;
  194. ; Draw point
  195. ;
  196.     cmp BitsPerPixel,24     ; Is it 24bits per pixel
  197.     jne isit15_16        ; if not goto isit15_16
  198.     mov ax,[bp+8]        ; al has blue pixel value
  199.     cld                     ; clear direction flag to increment
  200.     stosb                   ; write a byte in al to address in es:di
  201.     mov ax,[bp+6]         ; al has green pixel value
  202.     stosb
  203.     mov ax,[bp+4]          ; al has red pixel value
  204.     stosb
  205.     jmp fini                ; All three bytes written. Finish
  206. ;
  207. isit15_16:
  208.     cmp BitsPerPixel,16    ; Is it 16bits per pixel
  209.     mov Shift,3        ; adjust red bits shift factor
  210.     mov ShiftMask,255    ; adjust red/green bits mask
  211.     je drawit               ; Go write the color data else its 15bit
  212.     mov Shift,2             ; adjust for 15bits per pixel
  213.     mov ShiftMask,127       ; adjust red/green bit mask
  214. drawit:
  215.     mov cl,5        ; shift bits up factor
  216.     xor ax,ax        ; clear reg
  217.     mov bx,[bp+6]        ; get green value
  218.     and bx,00ffh
  219.     shl bx,cl        ; shift green up 5bits
  220.     mov ax,[bp+8]        ; get blue value
  221.     and ax,00FFh
  222.     add ax,bx        ; put portion of green with blue
  223.     cld
  224.     stosb            ; write the blue green value
  225.     mov ax,[bp+4]        ; get red value
  226.     and ax,00FFh
  227.     mov cx,Shift        ; get 15 or 16 bit shift factor
  228.     shl ax,cl        ; move red to correct position
  229.     add al,bh        ; put remaining green value with red
  230.     and ax,Shiftmask    ; mask unwanted bits
  231.     stosb            ; write the red green value
  232. fini:
  233.     pop dx                  ; Clean house and leave
  234.     pop cx
  235.     pop bx
  236.     Postfix
  237. draw_rgb endp
  238.  
  239.  
  240. ;
  241. ; Initialize the display
  242. ; Parameters:
  243. ;    Mode value to use
  244. ;
  245. public vgainit
  246. vgainit    proc far
  247. ;
  248. ; Set up call frame
  249. ;
  250.     Prefix
  251.     sub sp,256    ; Make local variable space
  252. ;
  253.     mov ax,vgadata    ; Load address of data segment
  254.     mov ds,ax    ; Set DS register
  255.  
  256. ;
  257. ; Get VGA information and set desired mode
  258. ;
  259.     mov ax,4f02h    ; VESA set mode function
  260.     mov bx,[bp+6]    ; Any mode I want !
  261.     int 10h
  262.  
  263.     push ss
  264.     pop es        ; Load es with value of ss
  265.     mov di,sp    ; Point index at 256 byte temp space
  266.     mov cx,[bp+6]
  267.     mov ax,4f01h    ; VESA get Super VGA mode information
  268.     int 10h
  269.  
  270.     mov ax,es:[di+4]  ;WinGranularity in k added 12/10/1992 djl
  271.     mov WinGran,ax
  272.     mov ax,es:[di+6]  ;WinSize in k
  273.     mov BlockSz,ax
  274.  
  275.     mov ax,es:[di+8]
  276.     mov WinAddr,ax    ;WinASegment  usually a000h
  277.  
  278. ;    mov ax,es:[di+12]        ;was rem ed from here by R.B.
  279. ;    mov word ptr WinFunc,ax  ;
  280.  
  281. ;    mov ax,es:[di+14]        ;
  282. ;    mov word ptr WinFunc+2,ax  ; to here
  283.  
  284.     mov ax,es:[di+16]
  285.     mov ScanWidth,ax      ;BytesPerScanLine
  286.  
  287.     mov ax,es:[di+25]     ;BitsPerPixel added 12/30/92 djl
  288.     and ax,255            ; djl
  289.     mov BitsPerPixel,ax    ; djl
  290.     cmp ax,15             ;is it a 15 bit mode? djl
  291.     jne lb0               ;skip if not 15 bit mode. djl
  292.     inc al                ;else force 15 bit modes to 16 bit modes. djl
  293. lb0:                          ;
  294.     shr al,3              ;convert BitsPerPixel to BytesPerPixel, djl
  295.     mov BytesPerPixel,ax    ;end of addition 12/30/92 djl
  296. ;
  297. ; Calculate block shift and end values
  298. ;
  299.     mov ax,BlockSz    ;ax = WinSize
  300.     mov bx,10
  301.     mov cx,03ffh
  302. lb1:
  303.     sar ax,1          ;divide ax by 2
  304.     inc bx            ;bx + 1
  305.     sal cx,1          ;mul